//
//  HXLPlaceViewController.m
//  On The Load
//
//  Created by 晓琳 on 15/11/8.
//  Copyright © 2015年 @@叶一闽. All rights reserved.
//

#import "HXLPlaceViewController.h"
#include "BaseButton.h"
#import "HXLDomesticView.h"
#import "HXLOverseasView.h"
#import "HXLTravelPlansViewController.h"
#import "HXLPlaceDetailViewController.h"
#import "HXLLeavesModel.h"
#import "DataHandle.h"
#import "HXLCityModel.h"

@interface HXLPlaceViewController ()<OverseasViewPopPlanViewController,DomesticViewPopPlaceViewControllerDelegate,ModelToPlanViewControllerDelegate>

@property (nonatomic, strong) BaseButton *domBtn;
@property (nonatomic, strong) BaseButton *overBtn;
@property (nonatomic, strong) HXLDomesticView *domView;
@property (nonatomic, strong) HXLOverseasView *overView;



@end

@implementation HXLPlaceViewController






- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"aaa");
    
        
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"搜索" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarAction:)];

    [self createButtonView];
    
    self.domView = [[HXLDomesticView alloc] initWithFrame:CGRectMake(0, 44*SCALEH, WIDTH, HEIGHT-44*SCALEH)];
    self.domView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.domView];
    self.domView.domViewDelegate = self;
    

    
    
    self.overView = [[HXLOverseasView alloc] initWithFrame:CGRectMake(0, 44*SCALEH, WIDTH, HEIGHT-44*SCALEH)];
    self.overView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:self.overView];
    [self.view bringSubviewToFront:self.domView];
    self.overView.myDelegate = self;
   
    
//    self.tabBarController.delegate = self;
    
    
}

#pragma mark - tabBarControllerDelegate
//- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
//    UINavigationController *na = (UINavigationController *)viewController;
//    NSLog(@"%@", na.viewControllers);
//    for (UIViewController *tempController in na.viewControllers) {
//        if (tempController != self) {
//            self.searchController.active = NO;
//        }
//    }
//}



- (void) rightBarAction:(UIBarButtonItem *)bar {

    HXLPlaceDetailViewController *searchVC = [[HXLPlaceDetailViewController alloc] init];
    searchVC.detailDelegate = self;
    [self.navigationController pushViewController:searchVC animated:YES];

    
}

- (void) createButtonView {
    
    self.domBtn = [BaseButton buttonWithType:UIButtonTypeCustom];
    self.domBtn.frame = CGRectMake(0, 0, WIDTH/2, 44*SCALEH);
    [self.view addSubview:self.domBtn];
    [self.domBtn setTitle:@"境内" forState:UIControlStateNormal];
    [self.domBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.domBtn addTarget:self action:@selector(domBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.overBtn = [BaseButton buttonWithType:UIButtonTypeCustom];
    self.overBtn.frame = CGRectMake(WIDTH/2, 0, WIDTH/2, 44*SCALEH);
    [self.view addSubview:self.overBtn];
    [self.overBtn setTitle:@"境外" forState:UIControlStateNormal];
    [self.overBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.overBtn addTarget:self action:@selector(overBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
}



- (void)domBtnAction:(UIButton *)btn {
    [self.overBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.domBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view bringSubviewToFront:self.domView];
    
}

- (void)overBtnAction:(UIButton *)btn {
    [self.domBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.overBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view bringSubviewToFront:self.overView];
}


//实现境外协议方法,回调选中的城市
- (void) popPlanviewController:(HXLLeavesModel *)city {
    
    [self.myDelegate getValueToPlanViewControllerVC:city];
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
//境内的协议方法
- (void)domViewPopPlaceViewController:(HXLLeavesModel *)model {
    
    [self.myDelegate getValueToPlanViewControllerVC: model];

    [self.navigationController popViewControllerAnimated:YES];
    
    
}

//搜索的协议方法
- (void)modelToPlanViewController:(HXLLeavesModel *)city {
    
    [self.myDelegate getValueToPlanViewControllerVC:city];
    [self.navigationController popViewControllerAnimated:YES];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
